<template>
    <el-dialog v-model="props.show" title="备注订单" width="30%" :before-close="handleClose">
        <el-form :model="note">
            <el-form-item label="添加">
                <el-input v-model="note" type="textarea" />
            </el-form-item>
        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="quxiao">取消</el-button>
                <el-button type="primary" @click="sure">
                    确认
                </el-button>
            </span>
        </template>
    </el-dialog>
</template>

<script lang="ts" setup>
import { reactive, ref, toRefs } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { user } from '@/api';

const dialogVisible = ref(true)


const state = reactive<{
    note: string
}>({
    note: ""
})
const handleClose = (done: () => void) => {
    emit("hide")
}
const props = defineProps({
    show: {
        type: Boolean,
        value: false
    },
    id: {
        type: Number,
        value: 0
    },
    status: {
        type: Number,
        value: 0
    }
})
const emit = defineEmits(['hide', 'resh'])

// 取消
const quxiao = () => {
    emit("hide")
}

// 确认
const sure = () => {
    if (props.id == 0) return
    if (props.id !== 0) {
        user.addordernote({ id: props.id, note: state.note, status: props.status }).then(res => {
            if (res.code == 200) {
                ElMessage.success("添加成功")
                emit("resh")
            }
        })
    }

    emit("hide")
}

let { note } = toRefs(state)
</script>
<style scoped>
.dialog-footer button:first-child {
    margin-right: 5px;
}
</style>